package com.itheima.controller;

import com.itheima.Vo.BusinessReportVo;
import com.itheima.Vo.MemberReportVo;
import com.itheima.Vo.SetmealReportVo;
import com.itheima.common.constant.MessageConstant;
import com.itheima.common.entity.Result;
import com.itheima.service.ReportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController
@Slf4j
@RequestMapping("/report")
public class ReportController {

    @Autowired
    private ReportService reportService;

    /**
     * 获取会员数量统计数据
     * @return
     */
    @GetMapping("/getMemberReport")
    public Result getMemberReport(){
        try {
            MemberReportVo reportVo = reportService.getMemberReport();
            return new Result(true, MessageConstant.GET_MEMBER_NUMBER_REPORT_SUCCESS,reportVo);
        } catch (Exception e) {
            return new Result(false, MessageConstant.GET_MEMBER_NUMBER_REPORT_FAIL,null);
        }
    }

    /**
     * 获取套餐占比统计数据
     * @return
     */
    @GetMapping("/getSetmealReport")
    public Result getSetmealReport(){
        try {
            SetmealReportVo setmealReportVo = reportService.getSetmealReport();
            return new Result(true,MessageConstant.GET_SETMEAL_COUNT_REPORT_SUCCESS,setmealReportVo);
        } catch (Exception e) {
            return new Result(false,MessageConstant.GET_SETMEAL_COUNT_REPORT_FAIL,null);
        }
    }

    /**
     * 获取运营统计数据
     * @return
     */
    @GetMapping("/getBusinessReportData")
    public Result getBusinessReportData(){
        try {
            BusinessReportVo businessReportVo = reportService.getBusinessReportData();
            return new Result(true,MessageConstant.GET_BUSINESS_REPORT_SUCCESS,businessReportVo);
        } catch (Exception e) {
            return new Result(false,MessageConstant.GET_BUSINESS_REPORT_FAIL,null);
        }
    }

    /**
     * 导出运营数据报表
     * @param response
     */
    @GetMapping("/exportBusinessReport")
    public void exportBusinessReport(HttpServletResponse response) throws IOException {
        reportService.exportBusinessReport(response);

    }

}
